package com.service.setting.impl;

import com.comm.R;
import com.entity.AdministrativeOffice;
import com.mapper.setting.SysOfficeMapper;
import com.service.setting.SysOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class SysOfficeServiceImpl implements SysOfficeService {

    @Autowired
    private SysOfficeMapper sysOfficeMapper;



    //查询所有科室信息
    @Override
    public R findOfficeList() {

        R r = new R();

        try {
            List<AdministrativeOffice> officeList = sysOfficeMapper.findOfficeList();

            if(officeList!=null){
                r.setCode(200);
                r.setMsg("查询成功");
                r.setData(officeList);
            }else{
                r.setCode(500);
                r.setMsg("查询失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出现故障了！！");
        }
        return r;
    }

    //根据科室名称查询科室信息
    @Override
    public R findOfficeByName(String office_name) {

        R r = new R();
        try {
            List<AdministrativeOffice> officeByName = sysOfficeMapper.findOfficeByName(office_name);

            if(officeByName!=null){
                r.setCode(200);
                r.setMsg("查询成功");
                r.setData(officeByName);
            }else{
                r.setCode(500);
                r.setMsg("查询失败,没有数据");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出现故障了！！");
        }
        return r;
    }

    //根据科室名新增一个科室
    @Override
    public R addOfficeByName(AdministrativeOffice office) {

        R r = new R();
        try {
            Integer row = sysOfficeMapper.addOfficeByName(office);
            if(row>0){
                r.setCode(200);
                r.setMsg("添加成功");
            }else{
                r.setCode(500);
                r.setMsg("添加失败,没有数据");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出现故障了！！");
        }
        return r;
    }

    //根据科室id修改科室的信息
    @Override
    public R updateOfficeById(AdministrativeOffice office) {

        R r = new R();

        try {
            Integer row = sysOfficeMapper.updateOfficeById(office);

            if(row>0){
                r.setCode(200);
                r.setMsg("修改成功");
            }else{
                r.setCode(500);
                r.setMsg("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出现故障了！！");
        }
        return r;
    }

    //根据科室Id删除科室信息
    @Override
    public R delOfficeById(AdministrativeOffice office) {
        R r = new R();
        try {
            Integer row = sysOfficeMapper.delOfficeById(office);

            if(row>0){
                r.setCode(200);
                r.setMsg("修改成功");
            }else{
                r.setCode(500);
                r.setMsg("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统出现故障了！！");
        }
        return r;
    }


}
